#pragma once

#include <vector>
#include <cstdint>
#include <cstddef>
#include "pcap.hpp"
#include "mirp.hpp"

class MIRPParser
{
private:
    std::vector<uint8_t> m_content;
    MIRPHeader* m_mirp_header;
    PcapPaser m_paser;
    void put(uint8_t *data, size_t data_len)
    {
        m_content.insert(m_content.end(), data, data + data_len);
    }

public:
    MIRPParser(std::string pcap_path) : m_paser(pcap_path) {}

    virtual ~MIRPParser()
    {
    }

    MIRPHeader* getMIRP()
    {
        auto ret = m_mirp_header;
        void *data_end = m_content.data() + m_content.size();

        if (ret && ret < data_end)
        {
            m_mirp_header = (MIRPHeader *)((uint8_t *)m_mirp_header + m_mirp_header->length + sizeof(MIRPHeader));
        }
        else
        {
            ret = nullptr;
        }
        return ret;
    }

    bool parse();
};